package com.artmofang.controller;

import com.artmofang.bo.StudentBO1;
import com.artmofang.common.utils.JSONResult;
import com.artmofang.pojo.MClass;
import com.artmofang.pojo.Student;
import com.artmofang.service.MClassService;
import com.artmofang.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@ApiIgnore
@RestController
public class HelloController {

    @Autowired
    private StudentService studentService;

    @Autowired
    private MClassService mClassService;

    @PostMapping("/deleteStudent")
    public Object deleteStudent(Integer studentId){
        int result = studentService.delete(studentId);
        System.out.println("-----------------------------");
        System.out.println(result);
        return result;
    }

    @PostMapping("/updateStudent")
    public Object updateStudent(Integer studentId,@RequestBody StudentBO1 studentBO1){
        int result = studentService.update(studentId, studentBO1);
        System.out.println("-----------------------------");
        System.out.println(result);
        return result;
    }

    @PostMapping("/saveStudent")
    public Object saveStudent(@RequestBody StudentBO1 studentBO1){
        int result = studentService.save(studentBO1);
        System.out.println("-----------------------------");
        System.out.println(result);
        return result;
    }

    @GetMapping("/classAll")
    public Object classAll(){
        List<MClass> result = mClassService.queryClassAll();
        return result;
    }

    @GetMapping("/test")
    public Object test(Integer studentId){
        Student student =  studentService.queryStudentById(studentId);
        return student;
    }

    @GetMapping("/hello")
    public Object hello(Integer studentId){

        System.out.println("**********************");
        System.out.println(studentId);

        return JSONResult.ok();

//        return studentService.queryStudentAll();
//        Map<String,Object> map = new HashMap<>();
//        map.put("studentId",studentId);
//        return studentService.queryStudentAndClassById(map);
    }

}
